package com.hmall.interceptors;

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

/**
 * @Author:篍
 * @Date: 2025/09/06 14:34
 * @Description:
 */
@Slf4j
@Configuration
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        Long userId = UserContext.getUser();
        log.warn("FeignInterceptor拦截获取用户信息:{}", userId);
        if (Objects.nonNull(userId)){
            requestTemplate.header("userId", String.valueOf(userId));
        }
    }
}
